<%
	bFromDate=Request("TxtFromDate")
	bToDate=Request("TxtToDate")
	bLoaiVB=Request("SLoaiVB")
%>
<!--#include file="..\CheckSession.inc"-->	
<!--#include file="..\Report.inc"-->
<SCRIPT language=VBScript runat=server>
function RP(inReportName,inSQL)
	ReportName = Session("APPL_PHYSICAL_PATH") & "\report\" &inReportName
	If Not IsObject ( session("oApp") ) Then
	    Set session ("oApp") = Server.CreateObject("CrystalRuntime.Application")
	End If
	If IsObject(session("oRpt")) then
		Set session("oRpt") = nothing
	End if	
	Set session("oRpt") = session("oApp").OpenReport(ReportName,1)
	session("oRpt").MorePrintEngineErrorMessages = False
	session("oRpt").EnableParameterPrompting = False
	session("oRpt").DiscardSavedData
	Session("oRpt").Database.Tables(1).ConnectionProperties("Data Source") = Session("ServerName")
	Session("oRpt").Database.Tables(1).ConnectionProperties("Initial Catalog") =Application("DataBaseName")	
	Session("oRpt").Database.Tables(1).ConnectionProperties("User ID") = Application("DBUser")
	Session("oRpt").Database.Tables(1).ConnectionProperties("Password") = Application("DBPass")
	session("oRpt").ParameterFields(1).SetCurrentValue cstr(bFromDate)
	session("oRpt").ParameterFields(2).SetCurrentValue cstr(bToDate)
	session("oRpt").SQLQueryString = CStr(inSQL)	
	If Err.Number <> 0 Then
	    Response.Write "Error " & Err.number & " " & Err.description 
	Else
	    If IsObject(session("oPageEngine")) Then
     	   set session("oPageEngine") = nothing
	    End If
	    set session("oPageEngine") = session("oRpt").PageEngine
	End If
end function
</SCRIPT>
<%
select case bLoaiVB
	case 1
		sSQL="Select Ngaynhan,sogoc,doitac,trichyeu,ykienxuly from vtden where baocao=1 and ngaynhan Between '"& SaveDate(bFromDate) &"' And '"& SaveDate(bToDate) &"' order by ngaynhan,doitac"
		CAll RP("rptDiemVTDen.rpt",sSQL)
	case 2
		sSQL="Select vtdi.*,phan_loai_di.ten_hinh_thuc from vtdi left outer join phan_loai_di on vtdi.phanloai=phan_loai_di.idloai where vtdi.baocao=1 and vtdi.ngayky Between '"& SaveDate(bFromDate) &"' And '"& SaveDate(bToDate) &"' order by phan_loai_di.ten_hinh_thuc,vtdi.ngaydi,vtdi.noinhan"
		CAll RP("rptDiemVTDi.rpt",sSQL)
	case 3
		sSQL="Select vtquyetdinh.*,phan_loai_qd.ten_hinh_thuc from vtquyetdinh left outer join phan_loai_qd on vtquyetdinh.phanloai=phan_loai_qd.idloai where vtquyetdinh.baocao=1 and vtquyetdinh.ngayky Between '"& SaveDate(bFromDate) &"' And '"& SaveDate(bToDate) &"' order by phan_loai_qd.ten_hinh_thuc,vtquyetdinh.ngaydi,vtquyetdinh.noinhan"
		CAll RP("rptDiemVTQD.rpt",sSQL)
end select
%><!-- #include file="SmartViewerActiveX.asp" -->
<%
	Conn.Close
	Set Conn=nothing
%>
<script language=vbscript runat=server>
Function FormatDate(vDate)
	   If Not IsNull(vDate) Then
	        vM = Right("0" & Month(vDate), 2)
	        vD = Right("0" & Day(vDate), 2)
	        vY = Right("19" & Year(vDate), 4)
	        FormatDate = vD & "/" & vM & "/" & vY
	   End If
End Function
Function SaveDate(vDate)
		dim bvitri1
		dim bvitri2
	   vDate=trim(cstr(vDate))
	   bvitri1=instr(1,vDate,"/")
	   bMonth=left(vDate,bvitri1-1)
	   bvitri2=instr(bvitri1+1,vDate,"/")
	   Dim Temp
	   Temp=right(vDate,len(vDate)-bvitri1)
	   bDay=left(Temp,bvitri2-bvitri1-1)
	   bYear=right(vDate,len(vDate)-bvitri2)
       SaveDate=bDay+"/"+bMonth+"/"+bYear
End Function
</script>